% Print Board

	   
initial_board([
        [0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ],
       [ 1, 0, 1, 0, 1, 0, 1, 0, 1, 0 ],
       [ 1, 0, 1, 0, 1, 0, 1, 0, 1, 0 ],
       [ 1, 0, 1, 0, 1, 0, 1, 0, 1, 0 ],
       [ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ],
       [ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ],
       [ 0, 2, 0, 2, 0, 2, 0, 2, 0, 2 ],
       [ 0, 2, 0, 2, 0, 2, 0, 2, 0, 2 ],
       [ 0, 2, 0, 2, 0, 2, 0, 2, 0, 2 ],
       [ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ]
       ]).

	   
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%         BOARD                 %%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%              PRINTING         %%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

printFrameBoarder(_):- write('###################################################'), nl.
printFrame(_):- 	   write('#     A   B   C   D   E   F   G   H   I   J       #'), nl.

printCellBorder_(0):- write('o'),write('    '), nl.
printCellBorder_(N):- N >= 1, write('o---'), N2 is N-1, printCellBorder_(N2).
printCellBorder(_):-  write('    '), printCellBorder_(10).

convert(H):- H == 0, write(' ').
convert(H):- H == 1, 
		player(P), (P == 1 -> write('x');
		write('*')).
convert(H):- H == 2, player(P), (P == 2 -> write('x');
		write('*')).
convert(H):- H == 3, write('8').
convert(H):- H == 4, write('8').
convert(H):- H == 5, write('H').
convert(H):- H == 6, write('H').

% Town, represented as H.

printLine_([]).
printLine_([H|T]):- write(' '), convert(H), write(' |'), printLine_(T).
printLine(Line, N):- printCellBorder(_), write(N), write('   |'), printLine_(Line), write('     '), write(N),  nl.

printLines_(_, N):- N >= 10, !.
printLines_([],_):- !.
printLines_([Line|Rest], N):- N < 10, printLine(Line,N), N2 is N+1, printLines_(Rest,N2).
printLines(Board):- printFrameBoarder(_), printFrame(_), printLines_(Board, 0), printCellBorder(_), printFrame(_), printFrameBoarder(_).

printBoard(Board):- abolish(player/1), assert(player(1)), printLines(Board).
printBoard(Board, P):- abolish(player/1), assert(player(P)), printLines(Board).

% The problem: using the variable defined as board1 does not work,
% however: printLines([[0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ],[ 0, 1, 0, 1, 0, 1, 0, 1, 0, 1 ],[ 0, 1, 0, 1, 0, 1, 0, 1, 0, 1 ],[ 0, 1, 0, 1, 0, 1, 0, 1, 0, 1 ],[ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ],[ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ],[ 0, 2, 0, 2, 0, 2, 0, 2, 0, 2 ],[ 0, 2, 0, 2, 0, 2, 0, 2, 0, 2 ],[ 0, 2, 0, 2, 0, 2, 0, 2, 0, 2 ],[ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ]]).
% works!
